package com.xinkong.lib_common.base
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.view.View

/**
 * Viewpage +fragment 基类
 * @author 黄训磊
 * @version 1.0.0
 * @since 2018-08-16 08:43
 */
class BaseViewPagerAdapter(fragmentManager: FragmentManager, val fragments: List<Fragment>, val title: Array<String>?) : FragmentStatePagerAdapter(fragmentManager) {
    override fun getCount(): Int {
        return fragments.size
    }

    /**
     * 返回的fragment
     */
    override fun getItem(position: Int): Fragment {
        return fragments[position]
    }


    /**
     * tabLayout 的文本内容
     */
    override fun getPageTitle(position: Int): CharSequence? {
        if (title != null) {
            return title[position]
        } else {
            return super.getPageTitle(position)
        }
    }

    /**
     *
     */
    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return super.isViewFromObject(view, `object`)
    }
}